package com.hddznet.uniplatform.sm.config;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.hddznet.uniplatform.sm.constant.StatusEnum;
import com.hddznet.uniplatform.sm.entity.SysDictEntity;
import com.hddznet.uniplatform.sm.service.ISysDictService;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
public class InitializingConfig implements InitializingBean {

	@Autowired
	private ISysDictService sysDictService;
	
	@Override
	public void afterPropertiesSet() throws Exception {
		log.info("InitializingConfig...");
		this.initDict();
	}
	
	private void initDict() {
		int total = sysDictService.count();
		if (total > 0) {
			return;
		}
		List<SysDictEntity> list = new ArrayList<>();
		list.add(this.newDict("隐患类型", "YH-Type"));
		list.add(this.newDict("隐患等级", "YH-Level"));
		list.add(this.newDict("特种作业类别", "ZY-Type"));
		list.add(this.newDict("特种作业等级", "ZY-Level"));
		list.add(this.newDict("特种作业大类", "ZY-Category"));
		list.add(this.newDict("特种作业检查项", "ZY-CheckItem"));
		list.add(this.newDict("特种作业指标监测", "ZY-Monitoring"));
		list.add(this.newDict("特种作业指标监测单位", "ZY-Monitoring-unit"));
		sysDictService.saveBatch(list);
	}
	
	private SysDictEntity newDict(String dictName, String dictCode) {
		SysDictEntity entity = new SysDictEntity();
		entity.setDictName(dictName);
		entity.setDictCode(dictCode);
		entity.setDictType(1);
		entity.setStatus(StatusEnum.Normal.key());
		entity.setCreater("sys");
		entity.setCreateTime(new Date());
		return entity;
	}
	
}
